package cn.hxzy.controller;


import cn.hxzy.domain.Courseware;
import cn.hxzy.domain.Video;
import cn.hxzy.response.R;
import cn.hxzy.response.StatusEnum;
import cn.hxzy.service.VideoService;
import cn.hxzy.util.AliOssUtil;
import com.aliyun.oss.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static org.jacoco.agent.rt.internal_43f5073.core.runtime.AgentOptions.OutputMode.file;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author niuyi
 * @since 2024-06-22
 */
@RestController
@RequestMapping("/video")
@CrossOrigin
public class VideoController {
    @Autowired
    public VideoService videoService;
    //根据小节ID查看视频
    @GetMapping("/selectVideoList/{sectionId}")
    public R<List<Video>> selectVideoList(@PathVariable Integer sectionId) {
        return R.success(videoService.selectVideoList(sectionId));

    }


    /**
     * 搜索框搜索视频
     * @param sectionId
     * @param videoName
     * @return
     */
    @GetMapping("/selectVideo")
    public R selectVideo(@RequestParam("sectionId") Integer sectionId,@RequestParam String videoName) {
        return R.success(new ArrayList<Video>());
    }
    //根据课件编号删除视频
    @Delete("/deleteVideo")
    public R deleteVideo(@RequestParam("videoId") Integer videoId) {
        return R.success("删除成功");
    }




    //新增视频
    @PostMapping("insertVideo")
    public R insert(MultipartFile file ) throws Exception {
       return R.success("");

    }





    //修改视频名称
    @PatchMapping("/updateVideoName")
    public R updateVideoName(@RequestParam("videoId") Integer videoId,@RequestParam("videoName") String videoName) {
        return R.success("修改成功");
    }
    //根据编号替换视频
    @PatchMapping("/updateVideo")
    public R updateVideo(@RequestParam("videoId") Integer videoId,@RequestParam("videoPoth") String videoPoth) {
        return R.success("修改成功");
    }
    //新增小节的视频
    @PostMapping("/saveVideo")
    public R saveVideo(@RequestBody Video video) {
        boolean save = videoService.save(video);
        if (save){
            return R.success(save);
        }
        return R.error(StatusEnum.SERVICE_ERROR);
    }

    @GetMapping("/selectVideoJd")
    public R selectJd(@RequestParam Integer userId,@RequestParam Integer videoId){
        return R.success(videoService.selectJd(userId, videoId));
    }

    @PostMapping("/updateVideoJd")
    public R updateJd(@RequestParam Integer userId,@RequestParam Integer videoId){
        return R.success(videoService.updateJd(userId, videoId));
    }

}

